//判断点击的哪个种类
function type(obj) {


    //获取到点击的种类值
    let val = $(obj).html();


    $("#type div > div").css({"font-weight":"","border-bottom": ""});
    $(obj).css({"font-weight":"bold","border-bottom": "3px solid green"});

    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;

        //总页数大于页码总数
        laypage.render({
            elem: 'demo1'
            ,count: getProductTypeSum(val) //数据总数
            ,limit:10 //页码
            ,jump: function(obj){
                let pageDatas ={"count":obj.count,"curr":obj.curr,"pages":obj.pages,"limit":obj.limit};
                // console.log("分页参数",obj)
                $.ajax({
                    url:"http://localhost:8080/back/front/newsFindByCategory",
                    dataType:'json',
                    data: {"page":pageDatas.curr,"limit":pageDatas.limit,"typeName":val},
                    success: function (res) {

                        console.log("某类新闻信息返回数据",res)

                        let val = '';
                        for (let i = 0; i < res.data.length; i++) {

                            val +=' <div >\n' +
                                '                                <div>\n' +
                                '                                    <div>['+res.data[i].typeName+']</div>\n' +
                                '                                    <div> '+res.data[i].title+'' +
                                '' +  '<span style="color: white;font: 20px Arial,sans-serif;background: #FF6600; ' +
                                'display:'+((res.data[i].isShow==1||res.data[i].isRecommend==1)?"":"none")+'">'+(res.data[i].isShow==1?"热":"新")+'</span>'+
                                '</div>\n' +

                                '                                </div>\n' +
                                '                                <div>\n' +
                                '                                    '+res.data[i].date+'\n' +
                                '                                </div>\n' +
                                '                            </div>'

                        }
                        $("#newsContent").html(val)


                    },
                })
            }
        })
    })









}

function getProductTypeSum(typeName) {
    let count;

    $.ajax({
        url:'http://localhost:8080/back/front/newsTypeSum',
        dataType:'json',
        data:{"typeName":typeName},
        async:false,//关闭异步
        success:function (data) {
            console.log("某类新闻的数量",data.data);
            count = data.data

        }
    })
    return count;
}